package com.java2108.hetong.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.java2108.hetong.entity.HtCategorie;
import com.java2108.hetong.mapper.HtCategorieMapper;
import com.java2108.hetong.service.IHtCategorieService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 合同分类信息表 服务实现类
 * </p>
 *
 * @author zhanggm
 * @since 2024-02-23
 */
@Primary
@DS("hetong")
@Service("htCategorieServiceImpl")
public class HtCategorieServiceImpl extends ServiceImpl<HtCategorieMapper, HtCategorie> implements IHtCategorieService {


    /**
     * 根据pid查询分类
     * @param parentId
     * @return
     */
    public HtCategorie getByParentId(Integer parentId) {
        QueryWrapper<HtCategorie> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("parentId", parentId);
        return getOne(queryWrapper);
    }

    /**
     * 根据id，查询孩子
     * 根据pid查询分类列表
     * @param id
     * @return
     */
    public List<HtCategorie> getListById(Integer id) {
        QueryWrapper<HtCategorie> queryWrapper = new QueryWrapper<>();
        if (id == null) {
            queryWrapper.isNull("parentId");
        } else {
            queryWrapper.eq("parentId", id);
        }
        return this.list(queryWrapper);
    }
}
